//
//  HomeNotiFScrollewView.m
//  ZJControlsClass
//
//  Created by mac on 2024/11/29.
//

#import "HomeNotiFScrollewView.h"
#import "HomeWebViewViewController.h"
#import "UUMarqueeView.h"

@interface HomeNotiFScrollewView ()<UUMarqueeViewDelegate>

@property (nonatomic,strong) UIView * follewView;
@property (nonatomic,strong) UIImageView * img;
@property (nonatomic, strong) UUMarqueeView *upwardSingleMarqueeView;
@property (nonatomic,strong) UIImageView * rightImg;


@end


@implementation HomeNotiFScrollewView


- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self){
        
        [self configUI];
        
    }
    return self;
}


-(void)configUI{
    
    [self addSubview:self.follewView];
    [self.follewView addSubview:self.img];
    [self.follewView addSubview:self.upwardSingleMarqueeView];
    [self.follewView addSubview:self.rightImg];
    
    [self.follewView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self).with.offset(ALIGN_WIDTH_PT(12));
        make.right.equalTo(self).with.offset(-ALIGN_WIDTH_PT(12));
        make.height.equalTo(@(ALIGN_HEIGHT_PT(36)));
    }];
    
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.follewView.mas_centerY);
        make.left.equalTo(self.follewView).with.offset(ALIGN_WIDTH_PT(7.5));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(22), ALIGN_WIDTH_PT(22))));
    }];
    
    self.upwardSingleMarqueeView = [[UUMarqueeView alloc] initWithFrame:CGRectMake(35, 0, SCREEN_WIDTH - 100, 36)];
    self.upwardSingleMarqueeView.delegate = self;
    self.upwardSingleMarqueeView.timeIntervalPerScroll = 2.0f;
    self.upwardSingleMarqueeView.timeDurationPerScroll = 2.0f;
    self.upwardSingleMarqueeView.touchEnabled = YES; // 开启点击事件
    [self.follewView addSubview:_upwardSingleMarqueeView];
    [self.upwardSingleMarqueeView reloadData];

    
    [self.rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.follewView.mas_centerY);
        make.right.equalTo(self.follewView).with.offset(-ALIGN_WIDTH_PT(12));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(10), ALIGN_HEIGHT_PT(15))));
    }];
    
}

-(void)setDataSource:(NSMutableArray *)dataSource{
    _dataSource = [HomeShowInfoModel mj_objectArrayWithKeyValuesArray:dataSource];
    [_upwardSingleMarqueeView start];
}


#pragma mark - UUMarqueeViewDelegate
- (NSUInteger)numberOfVisibleItemsForMarqueeView:(UUMarqueeView*)marqueeView {
    return 1;
}

- (NSUInteger)numberOfDataForMarqueeView:(UUMarqueeView*)marqueeView {

    return  self.dataSource.count;

}

- (void)createItemView:(UIView*)itemView forMarqueeView:(UUMarqueeView*)marqueeView {

    itemView.backgroundColor = [UIColor clearColor];
    UILabel *content = [[UILabel alloc] initWithFrame:itemView.bounds];
    content.font = FONT14;
    content.tag = 1001;
    content.textColor = [UIColor blackColor];
    [itemView addSubview:content];
}

- (void)updateItemView:(UIView*)itemView atIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView {
    UILabel *content = [itemView viewWithTag:1001];
    HomeShowInfoModel * model = self.dataSource[index];
    content.text = model.title;
}

-(void)didTouchItemViewAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView *)marqueeView{
    
    HomeShowInfoModel * model = self.dataSource[index];
    HomeWebViewViewController * vc = [HomeWebViewViewController new];
    vc.Id = model.id;
    [[SaViewControllerUtils currentViewController].navigationController pushViewController:vc animated:YES];
    
    NSLog(@"点击了 %ld",index);
}

#pragma mark -- 懒加载


-(UIView *)follewView{
    if (!_follewView){
        _follewView = [UIView new];
        _follewView.backgroundColor = COLOR_RGB(230, 237, 253);
        _follewView.layer.cornerRadius = 8;
        _follewView.layer.masksToBounds = YES;
    }
    return _follewView;
}

-(UIImageView *)img{
    if (!_img){
        _img = [UIImageView new];
        _img.image = [UIImage imageNamed:@"通知 1"];
    }
    return _img;
}

-(UIImageView *)rightImg{
    if (!_rightImg){
        _rightImg = [UIImageView new];
        _rightImg.image = [UIImage imageNamed:@"向右箭头"];
    }
    return _rightImg;
}



@end
